<?php

namespace App\Services\AuthOneDevice;

use App\Models\User;
use Tymon\JWTAuth\Facades\JWTAuth;
use Tymon\JWTAuth\Exceptions\TokenExpiredException;

class AuthOneDevice
{
	public function auth(User $user, string $token)
	{
		if ($user->last_token) {
			try {
				JWTAuth::setToken($user->last_token)->invalidate();
			} catch (TokenExpiredException $e) {}
		}
		
		$user->update(['last_token' => $token]);
	}
}
